package com.cloud.hotline.common.utils;

import java.text.DecimalFormat;
import java.util.List;

import com.cloud.hotline.api.bean.HotlineCalculateBean;
import com.cloud.hotline.api.bean.HotlineStreetCaculateBean;
import com.cloud.hotline.api.bean.HotlineUnitCaculateBean;

public class RankStatHelper {
	/**
	 * 诉求三率统计汇总
	 * 
	 * @param bean
	 * @return
	 */
	public static List<HotlineCalculateBean> rankStatRevisit(List<HotlineCalculateBean> records) {
		HotlineCalculateBean summary = new HotlineCalculateBean();
		int yxf = 0, jjs = 0, mys = 0;
		int pm = 1;
		double yjscz = 0;
		for (int i = 0; i < records.size(); i++) {
			HotlineCalculateBean record = records.get(i);
			yxf += Integer.valueOf(record.getYxf());// 有效回访
			jjs += Integer.valueOf(record.getJjs());// 解决数
			mys += Integer.valueOf(record.getMys());// 满意数
			double currentYjscz = Double.valueOf(record.getYjscz());// 预计双差值
			if (yjscz != currentYjscz) {
				pm = i + 1;
			}
			yjscz = currentYjscz;
			record.setPm(pm + "");
		}
		DecimalFormat df = new DecimalFormat("0.00");
		summary.setDw("统计汇总");
		summary.setYxf(yxf + "");// 有效訪
		summary.setXyl("100");// 响应率
		summary.setJjs(jjs + "");// 解决数
		summary.setJjl(df.format((double) jjs / (double) yxf * 100));// 解决率
		summary.setMys(mys + "");// 满意数
		summary.setMyl(df.format((double) mys / (double) yxf * 100));// 满意率
		summary.setZhpf(df.format(((double) jjs / (double) yxf * 0.3 + (double) jjs / (double) yxf * 0.35
				+ (double) mys / (double) yxf * 0.35) * 100));// 综合评分
		summary.setSlhj(df.format((double) jjs / (double) yxf * 100 + (double) mys / (double) yxf * 100)); // 双率合计
		summary.setYjscz(df.format((double) jjs / (double) yxf * 100 + (double) mys / (double) yxf * 100 - 130));// 预计双差值
		records.add(summary);
		return records;
	}

	/**
	 * 街道承办数据排名汇总
	 * 
	 * @param records
	 * @return
	 */
	public static List<HotlineStreetCaculateBean> rankStatStreet(List<HotlineStreetCaculateBean> records) {
		int jrzs = 0, jrszps = 0, jrqzps = 0, ljsl = 0;
		int pm = 1;
		int currentLjsl = 0;
		for (int i = 0; i < records.size(); i++) {
			HotlineStreetCaculateBean record = records.get(i);
			jrzs += record.getJrzs();// 今日总数
			jrszps += record.getJrszps();// 今日市指派数
			jrqzps += record.getJrqzps();// 今日区直派数
			ljsl += record.getLjsl(); // 累計數量
			if (currentLjsl != record.getLjsl()) {
				pm = i + 1;
			}
			currentLjsl = record.getLjsl();
			record.setPm(pm + "");
		}
		HotlineStreetCaculateBean summary = new HotlineStreetCaculateBean();
		summary.setJdmc("统计汇总");
		summary.setJrzs(jrzs);
		summary.setJrszps(jrszps);
		summary.setJrqzps(jrqzps);
		summary.setLjsl(ljsl);
		records.add(summary);
		return records;
	}

	/**
	 * 部门承办数据排名汇总
	 * 
	 * @param strCaclResults
	 */
	public static List<HotlineUnitCaculateBean> rankStatUnit(List<HotlineUnitCaculateBean> records) {
		int jrzs = 0, ljsl = 0;
		int pm = 1;
		int currentLjsl = 0;
		for (int i = 0; i < records.size(); i++) {
			HotlineUnitCaculateBean record = records.get(i);
			jrzs += record.getJrzs();// 今日总数
			ljsl += record.getLjsl(); // 累計數量
			if (currentLjsl != record.getLjsl()) {
				pm = i + 1;
			}
			currentLjsl = record.getLjsl();
			record.setPm(pm + "");
		}
		HotlineUnitCaculateBean summary = new HotlineUnitCaculateBean();
		summary.setMc("统计汇总");
		summary.setJrzs(jrzs);
		summary.setLjsl(ljsl);
		records.add(summary);
		return records;
	}
}
